public class isLine implements Judge{
    Point point1;
    Point point2;

    public isLine(Point a, Point b) {
        this.point1 = a;
        this.point2 = b;
    }

    //斜率接口实现
    @Override
    public double getSlope() {
        if (point1.getX() == point2.getX()) {
            return 1;                               //1表示斜率无穷大
        } else {
            return (double)((point1.getY()-point2.getY())/(point1.getX()-point2.getX()));
        }
    }


    //输出斜率接口实现
    @Override
    public void Slope() {
        if(getSlope() == 1) {
            if (isOnLine(new Point(0, 0))) {
                System.out.println("Slope: " + getSlope());
            } else {
                System.out.println("该射线的斜率为无穷大！");
            }
        } else {
            System.out.println("Slope: " + getSlope());
        }
    }

    //截距接口实现
    @Override
    public double getIntercept() {
        if(getSlope() == 1) {
            return 0;                           //0表示没有截距
        } else {
            return  point1.getY() - getSlope() * point1.getX();
        }
    }

    //输出截距接口实现
    @Override
    public void Intercept() {
        if (getIntercept() == 0) {
            if (getSlope() == 1) {
                System.out.println("该直线没有截距！");
            } else {
                System.out.println(getIntercept());
            }
        } else {
            System.out.println("Intercept: " + getIntercept());
        }
    }

    //是否在直线上
    @Override
    public boolean isOnLine(Point p) {
        if ((double) (p.getY()-point1.getY())/(p.getX()-point1.getX()) == getSlope()) {
            return true;
        } else {
            return false;
        }
    }

}
